﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Text;
using SMS.DAL;
using SMS.Entities;

namespace SMS.Web.Service
{
    // NOTE: You can use the "Rename" command on the "Refactor" menu to change the class name "StockMasterService" in code, svc and config file together.
    public class StockMasterService : IStockMasterService
    {
        public void DoWork()
        {
        }

        public List<StockMaster> LoadStockMasterList(string UserName, DateTime fromDate, DateTime endDate, out Entities.SMSException serviceError)
        {
            try
            {
                serviceError = null;
                return new PurchaseDA().GetObjectList(UserName, fromDate, endDate);
            }
            catch (Exception ex)
            {
                serviceError = new Entities.SMSException(ex);
                return null;
            }
        }

        public Entities.StockMaster GetCompleteStockMaster(string UserName, int StockID, out Entities.SMSException serviceError)
        {
            try
            {
                serviceError = null;
                return new PurchaseDA().GetCompleteObject(UserName, StockID);
            }
            catch (Exception ex)
            {
                serviceError = new Entities.SMSException(ex);
                return null;
            }
        }

        public int SaveStockMaster(string UserName, Entities.StockMaster obj, out Entities.SMSException serviceError)
        {
            try
            {
                serviceError = null;
                var retobj = new PurchaseDA().SaveObject(UserName, obj);
                return retobj.Stock_ID;
            }
            catch (Exception ex)
            {
                serviceError = new Entities.SMSException(ex);
                return -1;
            }
        }




        public List<ProductStockWise> GetProductsByStock(string UserName, int StockID, out SMSException serviceError)
        {
            try
            {
                serviceError = null;
                return new StockMasterDA().GetProductsByStock(UserName, StockID);
            }
            catch (Exception ex)
            {
                serviceError = new SMSException(ex);
                return null;
            }
        }

        public ProductStockWise GetCompleteProductStockDetail(string UserName, int Product_Stock_Id, out SMSException serviceError)
        {
            try
            {
                serviceError = null;
                return new StockMasterDA().GetCompleteProductStockWise(UserName, Product_Stock_Id);
            }
            catch (Exception ex)
            {
                serviceError = new SMSException(ex);
                return null;
            }
        }

        public int SaveProductStockWise(string UserName, ProductStockWise Obj, out SMSException serviceError)
        {
            try
            {
                serviceError = null;
                return new StockMasterDA().SaveObject(UserName, Obj).Product_Stock_ID;
            }
            catch (Exception ex)
            {
                serviceError = new SMSException(ex);
                return -1;
            }
        }
    }
}
